/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yassp.client;

import java.io.IOException;
import java.io.PipedInputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Milridor
 */
public class FileWriterThread extends Thread {
    private String hash;
    private PipedInputStream stream;
    
    public FileWriterThread(String fileHash, PipedInputStream stream) {
        this.hash = fileHash;
        this.stream = stream;
    }
    
    @Override
    public void run() {
        if(!FileStore.hashExist(hash)) {
            try {
                File f = new File(hash);
                FileStore.insert(f);
                f.deserialize(stream);
            } catch (IOException ex) {
                Logger.getLogger(FileWriterThread.class.getName()).log(Level.SEVERE, null, ex);
                return;
            }
        }
    }
    
}
